package com.itheima.question.controller;


import com.itheima.PageVo;
import com.itheima.Result;

import com.itheima.common.contants.RedisPicConstants;
import com.itheima.question.dto.PageDto;
import com.itheima.question.dto.QuestionDto;
import com.itheima.question.service.QuestionService;
import com.itheima.question.vo.QueryQuestionVo;
import com.itheima.question.vo.QuestionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/question")
@Api(value = "答题模块-题目接口",tags="admin_user",description = "用于实现后台题目的增删改查")
public class QuestionController {
@Autowired
private QuestionService questionService;



@ApiOperation("添加题目")
@PostMapping("/add")
    public Result addQuestion(@RequestBody QuestionDto questionDto){
    boolean result = questionService.addQuestion(questionDto);

    return new Result(result,result?"添加试题成功":"添加试题失败",null);
}


    /**
     * 分页显示题目列表
     */

    @PostMapping("/list")
    @ApiOperation("分页查询题目信息")
    public PageVo<QuestionVo> queryByPage(@RequestBody PageDto pageDto){
        return questionService.queryByPage(pageDto);
    }



    /**
     * 根据id查找题目信息
     */
    @GetMapping("/{id}")
    @ApiOperation("根据题目id查询题目信息")
    public QueryQuestionVo queryById(@PathVariable("id") String questionId){

        return questionService.queryById(questionId);

    }

    /**
     * 编辑题目
     */
    @PutMapping("/edit")
    @ApiOperation("编辑题目")
    public Result editQuestion(@RequestBody QueryQuestionVo queryQuestionVo){

        boolean result = questionService.editQuestion(queryQuestionVo);

        return new Result(result,null,result?"编辑题目成功":"编辑题目失败");

    }

    /**
     * 根据题目id删除题目
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据题目id删除题目信息")
    public Result deleteById(@PathVariable("id") String questionId){

        boolean result = questionService.deleteById(questionId);

        return new Result(result,null,result?"删除题目成功":"删除题目失败");

    }
}
